﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Collections;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class MP_MasFieldPositionGroups : System.Web.UI.UserControl
    {
        IFieldGroupBLL FieldGroup = new FieldGroupBLL();
        IEmployeeTypeBLL empTypeBLL = new EmployeeTypeBLL();

        private object _dataItem = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            FillDataToEmpType();

            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblSeq.Text = DataBinder.Eval(DataItem, "Sequence").ToString();
                    cmbEmpType.SelectedValue = DataBinder.Eval(DataItem, "EmployeeTypes.Sequence").ToString();
                    txtName.Text = DataBinder.Eval(DataItem, "Name").ToString();
                    txtDescr.Text = DataBinder.Eval(DataItem, "Description").ToString();
 
                }

                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }
        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

        public void FillDataToEmpType()
        {
            IList<EmployeeTypeInfo> InfoList = empTypeBLL.ListEmployeeTypes(null);

            cmbEmpType.DataSource = InfoList;
        }

        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            FieldGroup.Insert(txtName.Text.Trim()
                , txtDescr.Text.Trim()
                , Int32.Parse(cmbEmpType.SelectedValue)
                , 1);
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            FieldGroup.Update(Int32.Parse(lblSeq.Text.Trim())
                , txtName.Text.Trim()
                , txtDescr.Text.Trim()
                , Int32.Parse(cmbEmpType.SelectedValue)
                , 1);
           }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }
    }
}